# -*-coding:utf-8 -*- #
# ---------------------------------------------------------------------------
# ProjectName:   selenium_self
# FileName:      db.py
# Author:       test_liu
# Datetime:     2024/8/15 上午11:06
# Description:
# ---------------------------------------------------------------------------
from WebTest1.common.read_ini import ReadIni
import pymysql

class DB:
    def __init__(self):
        ini = ReadIni()
        self.host = ini.get_sql_connect('host')
        self.port = ini.get_sql_connect('port')
        self.user = ini.get_sql_connect('user')
        self.password = ini.get_sql_connect('password')
        self.db = ini.get_sql_connect('db')
        # 连接数据库
        self.conn = pymysql.connect(host=self.host, port=int(self.port), user=self.user, password=self.password, db=self.db)
        self.cursor = self.conn.cursor()

    def __del__(self):
        self.cursor.close()
        self.conn.close()

    # def delete(self, sql):
    def select_username(self, username):
        sql = f'select * from user where username = "{username}";'
        self.cursor.execute(sql)
        return self.cursor.fetchall()


if __name__ == '__main__':
    db = DB()
    print(db.select_username('学生S'))